//
//  JHSSickTypeController.m
//  detailVC
//
//  Created by chenWei on 2017/3/23.
//  Copyright © 2017年 陈伟. All rights reserved.
//

#import "JHSSickTypeController.h"
#import "JHSSicknessTypeModel.h"
#import <MJRefresh.h>

@interface JHSSickTypeController ()
@property (nonatomic,strong) NSArray<JHSSicknessTypeModel *> *modelArr;

@end

@implementation JHSSickTypeController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.modelArr=[NSArray array];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];

    [SVProgressHUD showProgress:8.8 status:@"加载数据中"];
    [self loadSickTypeData];
    
}

-(void)setupMJRefresh{
    
}

//加载网络数据
-(void)loadSickTypeData{
    if (self.bigType==0) {
        return;
    }
    
    NSString *url = @"http://iosapi.itcast.cn/doctor/searchCI3List.json.php";
    NSString *strNULL=@"";
    NSDictionary *parameters = @{@"page":@1,@"page_size":@15,@"ci1_id":@(self.bigType),@"keyword":strNULL};
    [JHSSicknessTypeModel sicknessTypeNetDataWithURL:url withParameters:parameters withSuccessBlock:^(id responceBoby) {
        _modelArr=responceBoby;
        [self.tableView reloadData];
        [SVProgressHUD dismiss];
    } withFailureBlock:^(NSError *error) {
        NSLog(@"JHSSickTypeController网络请求失败");
    }];

    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return _modelArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    JHSSicknessTypeModel *modelDic=[JHSSicknessTypeModel yy_modelWithJSON:_modelArr[indexPath.row]];
    
        cell.textLabel.text = [NSString stringWithFormat:@"%@",modelDic.ci3_name];

    return cell;
    
}

//MARK:选中不同cell的事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    NSLog(@"%@",[JHSSicknessTypeModel yy_modelWithJSON:_modelArr[indexPath.row]]);
    
    JHSSicknessTypeModel *model=[JHSSicknessTypeModel yy_modelWithJSON:_modelArr[indexPath.row]];
//    NSLog(@"%zd---,",model.ci2_id);
    
    [self.delegate setSickType:self withModel:model];
    [self.navigationController popViewControllerAnimated:YES];

    
    
}


-(void)clickedItemBtn:(UIBarButtonItem *)btn{
//    NSLog(@"点击了确定");
//    [self.delegate ]
    
}




@end
